﻿@model RXY_Mall.Application.Order.Dto.GetReturnOutput

@section CSS{
    <link href="~/Content/css/layerui/layui.css" rel="stylesheet" />
}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            退换货
            <small>详情</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">销售管理</a></li>
            <li><a href="/Order/ReturnOrders">退换货列表</a></li>
            <li class="active">退换货详情</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">售后信息</h3>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form role="form">
                        <div class="box-body">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label>服务单号:</label>
                                    <label>@Model.return_no</label>
                                </div>
                                <div class="form-group">
                                    <label>服务状态:</label>
                                    <label>@Model.return_status</label>
                                </div>
                                <div class="form-group-lg">
                                    <label>下一步:</label>
                                    @if (Model.return_status == "提交申请")
                                    {
                                        //审核
                                        <button type="button" onclick="OpenAudit(@Model.return_id)" class="btn btn-default" data-toggle="modal" data-target="#modal-audit">审核</button>
                                    }
                                    else if (Model.return_status == "审核通过")
                                    {
                                        if (Model.return_type == "我要退款")
                                        {
                                            <button type="button" onclick="OpenRefund(@Model.return_id)" class="btn btn-default" data-toggle="modal" data-target="#modal-refund">退款</button>
                                        }
                                    }
                                    else if (Model.return_status == "退货信息")
                                    {
                                        if (Model.return_type == "我要退货退款")
                                        {
                                            <button type="button" onclick="OpenRefund(@Model.return_id)" class="btn btn-default" data-toggle="modal" data-target="#modal-refund">商家确认收货并退款</button>
                                        }
                                        else
                                        {
                                            //商家确认收货
                                            <button type="button" onclick="OpenShipment(@Model.return_id)" class="btn btn-default" data-toggle="modal" data-target="#modal-shipment">商家确认收货</button>
                                        }
                                    }
                                    else if (Model.return_status == "退款中")
                                    {
                                        <button type="button" onclick="OpenRefund(@Model.return_id)" class="btn btn-default" data-toggle="modal" data-target="#modal-refund">退款</button>
                                    }
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label>订单号:</label>
                                    <a href="/Order/GoodsOrder/@Model.order_id" target="_blank" style="color:seagreen">@Model.order_no</a>
                                </div>
                                <div class="form-group">
                                    <label>申请时间:</label>
                                    <label>@Model.add_time</label>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                    </form>
                </div>
                <!-- /.box -->
            </div>
        </div>
        <div>
            <ul class="timeline">
                @* 申请 *@
                <!-- timeline time label -->
                <li class="time-label">
                    <span class="bg-red">
                        @Model.add_time.ToShortDateString()
                    </span>
                </li>
                <!-- /.timeline-label -->
                <!-- timeline item -->
                <li>
                    <!-- timeline icon -->
                    <i class="fa fa-user bg-blue"></i>
                    <div class="timeline-item">
                        <span class="time"><i class="fa fa-clock-o"></i>@Model.add_time.ToShortTimeString()</span>
                        <h3 class="timeline-header"><a href="#">申请售后</a></h3>
                        <div class="timeline-body">
                            <div class="form-group">
                                <label>服务类型:</label>
                                <label>@Model.return_type</label>
                            </div>
                            <div class="form-group">
                                <label>服务原因:</label>
                                <label>@Model.return_reason</label>
                            </div>
                            <div class="form-group">
                                <label>申请说明:</label>
                                <label>@Model.request.remark</label>
                            </div>
                            <div class="form-group">
                                <label>联系人:</label>
                                <label>@Model.request.contact_name</label>
                            </div>
                            <div class="form-group">
                                <label>联系电话:</label>
                                <label>@Model.request.contact_mobile</label>
                            </div>
                            <div class="form-group">
                                <label>上传凭证:</label>
                                @foreach (var item in Model.request.pictures)
                                {
                                    <img style="margin:10px;" src="@item" width="100" height="100" />
                                }
                            </div>
                        </div>
                    </div>
                </li>
                @*审核时间*@
                @if (Model.audit != null)
                {
                    <li class="time-label">
                        <span class="bg-red">
                            @Model.audit.add_time.ToShortDateString()
                        </span>
                    </li>
                    <li>
                        <!-- timeline icon -->
                        <i class="fa fa-user-secret bg-blue"></i>
                        <div class="timeline-item">
                            <span class="time"><i class="fa fa-clock-o"></i>@Model.audit.add_time.ToShortTimeString()</span>
                            <h3 class="timeline-header"><a href="#">审核</a></h3>
                            <div class="timeline-body">
                                <div class="form-group">
                                    <label>审核状态:</label>
                                    <label>@Model.audit.is_pass</label>
                                </div>
                                <div class="form-group">
                                    <label>审核内容:</label>
                                    <label>@Model.audit.audit_note</label>
                                </div>
                                <div class="form-group">
                                    <label>审核备注:</label>
                                    <label>@Model.audit.remark</label>
                                </div>
                            </div>
                        </div>
                    </li>
                }
                @*卖家发货时间*@
                @if (Model.buyer_waybill != null)
                {
                    <li class="time-label">
                        <span class="bg-red">
                            @Model.buyer_waybill.add_time.ToShortDateString()
                        </span>
                    </li>
                    <li>
                        <!-- timeline icon -->
                        <i class="fa fa-user bg-blue"></i>
                        <div class="timeline-item">
                            <span class="time"><i class="fa fa-clock-o"></i>@Model.buyer_waybill.add_time.ToShortTimeString()</span>
                            <h3 class="timeline-header"><a href="#">买家退货信息</a></h3>
                            <div class="timeline-body">
                                <div class="form-group">
                                    <label>快递公司:</label>
                                    <label>@Model.buyer_waybill.company_name</label>
                                </div>
                                <div class="form-group">
                                    <label>运单号:</label>
                                    <label>@Model.buyer_waybill.waybill_no</label>
                                </div>
                            </div>
                        </div>
                    </li>
                }
                @*卖家发货时间*@
                @if (Model.merchant_waybill != null)
                {
                    <li class="time-label">
                        <span class="bg-red">
                            @Model.merchant_waybill.add_time.ToShortDateString()
                        </span>
                    </li>
                    <li>
                        <!-- timeline icon -->
                        <i class="fa fa-user-secret bg-blue"></i>
                        <div class="timeline-item">
                            <span class="time"><i class="fa fa-clock-o"></i>@Model.merchant_waybill.add_time.ToShortTimeString()</span>
                            <h3 class="timeline-header"><a href="#">商家发货信息</a></h3>
                            <div class="timeline-body">
                                <div class="form-group">
                                    <label>快递公司:</label>
                                    <label>@Model.merchant_waybill.company_name</label>
                                </div>
                                <div class="form-group">
                                    <label>运单号:</label>
                                    <label>@Model.merchant_waybill.waybill_no</label>
                                </div>
                            </div>
                        </div>
                    </li>
                }
                @if (Model.refund_amount != null && Model.refund_amount > 0)
                {
                    <li class="time-label">
                        <span class="bg-red">
                            @{ var shop_refund_time = (DateTime)Model.shop_refund_time;}
                            @shop_refund_time.ToShortDateString()
                        </span>
                    </li>
                    <li>
                        <!-- timeline icon -->
                        <i class="fa fa-user bg-blue"></i>
                        <div class="timeline-item">
                            <span class="time"><i class="fa fa-clock-o"></i>@shop_refund_time.ToShortTimeString()</span>
                            <h3 class="timeline-header"><a href="#">退款信息</a></h3>
                            <div class="timeline-body">
                                <div class="form-group">
                                    <label>退款金额:</label>
                                    <label>@Model.refund_amount</label>
                                </div>
                            </div>
                        </div>
                    </li>
                }
                @if (Model.complete_time != null)
                {
                    <li class="time-label">
                        <span class="bg-red">
                            @{ var complete_time = (DateTime)Model.complete_time;}
                            @complete_time.ToShortDateString()
                        </span>
                    </li>
                    <li>
                        <!-- timeline icon -->
                        <i class="fa fa-user bg-blue"></i>
                        <div class="timeline-item">
                            <span class="time"><i class="fa fa-clock-o"></i>@complete_time.ToShortTimeString()</span>
                            <h3 class="timeline-header"><a href="#">服务完成</a></h3>
                        </div>
                    </li>
                }
            </ul>
        </div>
    </section>

    <div class="modal fade" id="modal-audit" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title">审核信息</h4>
                </div>
                <form id="UpdateAudit" class="form-horizontal" method="post" action="~/Return/UpdateReturnAudit">
                    @Html.AntiForgeryToken()
                    <input id="audit_return_id" name="return_id" type="hidden" value="" />
                    <div class="modal-body">
                        <div class="box-body">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">审核状态:</label>
                                <div class="col-sm-10">
                                    <select class="form-control" id="is_pass" name="is_pass">
                                        <option value="0">不通过</option>
                                        <option value="1">通过</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">审核留言:</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" rows="3" id="audit_note" name="audit_note" placeholder="审核留言"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">收货地址:</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" rows="3" id="audit_remark" name="audit_remark" placeholder="收货地址"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="UpdateAudit()" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="modal-shipment" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title">填写发货信息</h4>
                </div>
                <form id="UpdateReturnShipment" class="form-horizontal" method="post" action="~/Return/UpdateReturnShipment">
                    @Html.AntiForgeryToken()
                    <input id="shipment_return_id" name="return_id" type="hidden" value="" />
                    <div class="modal-body">
                        <div class="box-body">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">快递公司:</label>
                                <div class="col-sm-10">
                                    <select class="form-control" id="logistics_name" name="logistics_name">
                                        @foreach (var item in ViewBag.Logistics)
                                        {
                                            var sss = item.logistics_name + "," + item.logistics_telephone;
                                            <option value="@sss"> @item.logistics_name</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">运单号:</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="waybill_no" name="waybill_no" placeholder="运单号">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="UpdateReturnShipment()" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="modal-refund" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title">退款信息</h4>
                </div>
                <form id="UpdateReturnRefund" class="form-horizontal" method="post" action="~/Return/UpdateReturnRefund">
                    @Html.AntiForgeryToken()
                    <input id="refund_return_id" name="return_id" type="hidden" value="" />
                    <div class="modal-body">
                        <div class="box-body">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">订单金额:</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="order_amount" name="order_amount" value="@Model.order_amount" disabled>
                                </div>
                            </div>
                            @*<div class="form-group">
                                    <label class="col-sm-2 control-label">退款金额:</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control" id="refund_amount" name="refund_amount" placeholder="退款金额">
                                    </div>
                                </div>*@
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="UpdateReturnRefund()" class="btn btn-primary">确认退款</button>
                    </div>
                </form>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
</div>

@section JS{
    <script>
        function OpenAudit(order_id) {
            $("#audit_return_id").val(order_id);
        }
        function UpdateAudit() {
            var logistics = $("#audit_note").val();
            //var waybill_no = $("#waybill_no").val();
            if (logistics == 0) { alert("审核留言不能为空"); return; }
            //if (waybill_no.length == 0) { alert("运单号不能为空"); return; }
            $('#UpdateAudit').submit();
        }

        function OpenRefund(order_id) {
            $("#refund_return_id").val(order_id);
        }
        function UpdateReturnRefund() {
            var refund_amount = $("#refund_amount").val();
            var order_amount = $("#order_amount").val();
            if (refund_amount == 0) { alert("退款金额不能为空"); return; }
            if(refund_amount>order_amount){ alert("退款金额不能大于订单金额"); return; }
            $('#UpdateReturnRefund').submit();
        }

        function OpenShipment(order_id) {
            $("#shipment_return_id").val(order_id);
        }
        function UpdateReturnShipment() {
            var logistics = $("#logistics").val();
            var waybill_no = $("#waybill_no").val();
            if (logistics == 0) { alert("请选择物流公司"); return; }
            if (waybill_no.length == 0) { alert("运单号不能为空"); return; }
            $('#UpdateReturnShipment').submit();
        }
    </script>
}


